package edu.zut.cs.software.cms.module.all.dao;

import java.util.List;

import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import edu.zut.cs.software.cms.base.dao.GenericDao;
import edu.zut.cs.software.cms.module.all.domain.All;

/**
 * all entity's dao interface
 * 
 * @author 42276
 *
 */
@Repository
public interface AllDao extends GenericDao<All, Long> {
	/**
	 * return an "All" entity by its "username"
	 * @param username
	 * @return
	 */
	@Query(value="  SELECT * FROM `cms`.`t_all` WHERE `username`=?1 ",nativeQuery=true)
	All getByUsername(@Param("username") String username);

	
	/**
	 * 通过id返回一个All对象
	 * @param id
	 * @return
	 */
	@Query(value="  SELECT * FROM `cms`.`t_all` WHERE `id`=?1 ",nativeQuery=true)
	All selectById(@Param("id") Long id);

	
	
	/**
	 * 返回All实体的全部数据
	 * @return
	 */
	@Query(value="  SELECT * FROM `cms`.`t_all` ",nativeQuery=true)
	List<All> selectAlls();
	
	//select COUNT(*) from t_all where username='201808064600';
	@Query(value="  SELECT COUNT(*) FROM `cms`.`t_all` WHERE `username`=?1 ",nativeQuery=true)
	int IfOneExist(@Param("username") String username);
}